package com.letoken.platform.pub.annotation.sms;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
@Component
public class AccountValidator implements ConstraintValidator< AccountCheck, Object> {



    @Override
    public void initialize(AccountCheck constraintAnnotation) {
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context ) {
        if (StringUtils.isEmpty(value)) {
            context.disableDefaultConstraintViolation();
            context.buildConstraintViolationWithTemplate("参数异常").addConstraintViolation();
            return false;
        }

        /*Pattern move = Pattern.compile(
                "^((130)|(131)|(132)|(133)|(134)|(135)|(136)|(137)|(138)|(139)|(145)" + "|(147)|(149)|(150)|(151)|(152)|(153)|(155)|(156)|(157)|(158)|(159)|(166)|(171)|(172)|(173)|(175)"
                        + "|(176)|(177)|(178)|(180)|(181)|(182)|(183)|(184)|(185)|(186)|(187)" + "|(188)|(189)|(190)|(191)|(193)|(195)|(196)|(197)|(198)|(199))\\d{8}$");*/

        Pattern move = Pattern.compile(
                "[0-9]+");

        if (!move.matcher((String)value).matches()) {
            return false;
        }
        return true;
    }

}
